<template>
  <div id="orgChart">
    <div class="title"></div>
    <div class="content">
      <div id="infovis" style="height: 600px;width: 100%"></div>

    </div>
  </div>
</template>

<script>
  export default {
    name:'orgChart',
    created(){
      this.changeData = this.handleData([],this.orgData);

    },
    mounted(){
    	this.$nextTick(function () {
        this.init();
      })
    },
    data:function () {
      return {
        changeData:{},
        orgData:[{
          orgIdQueue: "0,",
          orgName: "深圳市理才网信息技术有限公司",
          parentOrgId: 0,
          children: [
            {
              orgIdQueue: "0,1,2,",
              orgName: "HR",
              parentOrgId: 2,
              children: [ ],
              orgShortName: 2,
              orgId: 40
            },
            {
              orgIdQueue: "0,1,",
              orgName: "softDev",
              parentOrgId: 1,
              children: [
                {
                  orgIdQueue: "0,1,2,",
                  orgName: "HR",
                  parentOrgId: 2,
                  children: [ ],
                  orgShortName: 2,
                  orgId: 3
                },
                {
                  orgIdQueue: "0,1,2,",
                  orgName: "HR",
                  parentOrgId: 2,
                  children: [ ],
                  orgShortName: 2,
                  orgId: 1222

                },
                {
                  orgIdQueue: "0,1,2,",
                  orgName: "HR",
                  parentOrgId: 2,
                  children: [ ],
                  orgShortName: 2,
                  orgId: 12
                },
                {
                  orgIdQueue: "0,1,2,",
                  orgName: "HR",
                  parentOrgId: 2,
                  children: [ ],
                  orgShortName: 2,
                  orgId: 4
                }
              ],
              orgShortName: 1,
              orgId: 2
            }
          ],
          orgShortName: 0,
          orgId: 1
        }
      ]
      }
    },
    methods : {
      handleData(obj,data){
        for(var i=0;i<data.length;i++){
          obj.push({
            id:'node'+ data[i].orgId,
            name:data[i].orgName,
            data:{
              orgId:data[i].orgId,
              orgName:data[i].orgName,
              orgIdQueue:data[i].orgIdQueue,
              parentOrgId:data[i].parentOrgId,
              orgShortName:data[i].orgShortName
            },
            children:[],
          })
          if(data[i].children.length){
            this.handleData(obj[i].children,data[i].children);
          }
        }
        return obj
      },
      init(){
      	var t = this;
        var st = new $jit.ST({
          //id of viz container element
          injectInto: 'infovis',
          orientation:'top',
          subtreeOffset: 1,
          siblingOffset: 2,
          indent:10,
          //set duration for the animation
          duration: 500,
          //set animation transition type
          transition: $jit.Trans.Quart.easeInOut,
          //set distance between node and its children
          levelDistance: 100,
          //enable panning
          Navigation: {
            enable:true,
            panning:true
          },
          Node: {
            height: 120,
            width: 180,
            type: 'rectangle',
            overridable: true
          },

         /* Edge: {
            type: 'bezier',
            overridable: true
          },*/

          onBeforeCompute: function(node){

          },

          onAfterCompute: function(){

          },

          //This method is called on DOM label creation.
          //Use this method to add event handlers and styles to
          //your node.
          onCreateLabel: function(label, node){
            label.id = node.id;
            var labelHtml = `
              <div class="label-content">
                <div class="label-panel">
                  <div class="header">aa</div>
                  <div class="content">ff</div>
                </div>
              </div>
            `
            label.innerHTML = labelHtml;
            label.onclick = function(){
              st.onClick(node.id);
            };
          },

          //This method is called right before plotting
          //a node. It's useful for changing an individual node
          //style properties before plotting it.
          //The data properties prefixed with a dollar
          //sign will override the global node style properties.
          onBeforePlotNode: function(node){
            //add some color to the nodes in the path between the
            //root node and the selected node.
            if (node.selected) {
              //node.data.$color = "#ff7";
            }
            else {
              delete node.data.$color;
              //if the node belongs to the last plotted level
              if(!node.anySubnode("exist")) {
                //count children number
                var count = 0;
                node.eachSubnode(function(n) { count++; });
                //assign a node color based on
                //how many children it has
              //  node.data.$color = ['#aaa', '#baa', '#caa', '#daa', '#eaa', '#faa'][count];
              }
            }
          },

          onBeforePlotLine: function(adj){
            if (adj.nodeFrom.selected && adj.nodeTo.selected) {
             // adj.data.$color = "#eed";
              adj.data.$lineWidth = 3;
            }
            else {
              delete adj.data.$color;
              delete adj.data.$lineWidth;
            }
          }
        });
        //load json data
        st.loadJSON(t.changeData[0]);
        //compute node positions and layout
        st.compute();
        //optional: make a translation of the tree
        st.geom.translate(new $jit.Complex(0, -100), "current");
        //emulate a click on the root node.
        st.onClick(st.root);
        //end
      }
    }
  }

</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style rel="stylesheet/scss" type="text/css" lang="scss">

  @import "src/assets/css/variable";

    .node{
      padding: 0;
      border-radius: 4px;
    }

  .label-content{
    width: 180px;
    background-color: #fff;
    border-radius: 4px ;
    .label-panel{
      width: 180px;
      margin: 0 auto;
      .header{
        height: 30px;
        line-height: 30px;
        color: #fff;
        background-color: $baseColor
      }
      .content{
        background-color: #fff;
        height: 90px;
        border: 1px $baseBorderColor solid;
      }
    }
  }
  #orgChart{

  }
  .more_search_content{
    width: 240px;
    padding: 24px;
  }
  .org_chart {
    .main_content {

    }
    .top {
      height: 60px;
      line-height: 60px;
      background-color: #eee;
      text-align: center;
      position: relative;
      z-index: 100;
      .search_content {
        position: relative;
        .search_drop{
          margin: 12px;
        }
        .search_input {
          width: 300px;
          height: 28px;
          line-height: 28px;
          padding: 0 12px;
          border-radius: 4px 0 0 4px;
          position: relative;
          .el-input__icon{

          }
          .search_btn{
            color: #5ba3e5 ;
            font-weight: bold;
            font-size: 18px;
            width: 40px;
            cursor: pointer;
            transition: transform .15s ease-out;
            &:hover{
              transform: scale(1.1);
            }
          }
        }
        .drop_down_btn {
          display: inline-block;
          width: 26px;
          height: 26px;
          line-height: 26px;
          border: 1px #c9c9c9 solid;
          border-left: none;
          border-right: none;
          background-color: #fff;
          vertical-align: middle;
          cursor: pointer;
          &:hover {
            opacity: .5;
          }
        }
        .search_panel {
          display: inline-block;
          position: relative;
        }
        .search_box {
          position: absolute;
          top: 45px;
          left: 0;
          width: 235px;
          padding: 20px;
          background-color: #fff;
          border: 1px #c9c9c9 solid;
          border-top: none;
          box-shadow: 0px 3px 8px 1px #ddd;
          line-height: 40px;
          display: none;
          border-radius: 0 0 4px 4px;
          .search_btn_div {
            text-align: right;
            padding: 12px 12px 0 0;
          }
          label {
            display: inline-block;
            width: 60px;
            padding-right: 10px;
            text-align: right;
            font-size: 12px;
          }
          input {
            width: 140px;
            height: 30px;
            line-height: 30px;
            border-radius: 2px;
          }
        }
      }

      .scale_content {
        > span {
          display: inline-block;
          width: 30px;
          height: 30px;
          line-height: 30px;
          text-align: center;
          background-color: #fff;
          border: 1px #c9c9c9 solid;
          cursor: pointer;
          &:hover {
            color: $activeColor;
          }
          &.add {
            border-left: none;
            border-left: none;
          }
          &.minus {
            border-right: none;
          }
        }
        > input {
          width: 40px;
          height: 32px;
          padding: 0 6px;
          text-align: center;
          box-sizing: border-box;
        }
      }
    }
    .org_map_panel {
      min-height: 400px;
      transition: all .3s;
      .top_content, .bottom_content {
        display: block;
        text-align: center;
        position: relative;
        transition: all .3s;
        padding: 40px 0;
      }
      .top_content {
        .panel_item {
          .panel_title {
            background-color: $activeColor;
          }
          &.archive {
            .panel_title {
              background-color: #bbb;
              .edit_item {
                display: none !important;
              }
            }
            .hidden_div {
              background-color: #bbb;
              display: none !important;
            }

          }
        }
      }
      .hidden_div {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        background-color: $activeColor;
        border-radius: 0 0 8px 8px;
        color: #fff;
        transition: all .25s;
        height: 0;
        overflow: hidden;
        > div {
          height: 50%;
          text-align: center;
          line-height: 80px;
          color: #fff;
          font-size: 16px;
          > a {
            position: relative;
            color: #fff;
            .count {
              position: absolute;
              right: -25px;
              top: 0;
              background-color: #ed6c2b;
              padding: 0 5px;
              line-height: 20px;
            }
            &.active:hover {
              text-decoration: underline;
            }
          }
        }
      }
      .bottom_content {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        position: relative;
        .panel_item {
          .panel_title {
            background-color: #02c5c5;
          }
          .hidden_div {
            background-color: #02c5c5;
          }
          &:first-child:before {
            content: '';
            position: absolute;
            width: 1px;
            height: 30px;
            left: calc(50% + 3px);
            top: -40px;
            border-left: 1px #c9c9c9 solid;
          }
          &.line:before {
            content: '';
            position: absolute;
            width: 100%;
            height: 30px;
            left: calc(50% + 2px);;
            top: -40px;
            border-top: 1px #c9c9c9 solid;
            border-right: 1px #c9c9c9 solid;
          }

          &.archive {
            .panel_title {
              background-color: #bbb;
              .edit_item {
                display: none !important;
              }
            }
            .hidden_div {
              background-color: #bbb;
              display: none !important;
            }

          }
        }
        &:before {
          content: '';
          position: absolute;
          width: 1px;
          height: 30px;
          left: calc(50% + 3px);
          top: -30px;
          transition: all .25s;
          background-color: #c9c9c9;
        }
      }
    }

    .fade-transition {
      transition: all .2s ease;
      opacity: 1;
      transform: translate(0, 0);
    }

    .fade-enter, .fade-leave {
      opacity: 0;
      transform: translate(0, -10%);
    }
  }

  .panel_item {
    position: relative;
    display: inline-block;
    box-sizing: border-box;
    padding: 10px 20px;
    .panel_item_content {
      width: 180px;
      height: 120px;
      position: relative;
      border-radius: 8px;
      box-shadow: 1px 1px 10px 2px #ccc;
      .panel_title {
        position: relative;
        background-color: #02c5c5;
        border-radius: 8px 8px 0 0;
        border-bottom: 1px #ddd solid;
        font-size: 16px;
        line-height: 27px;
        height: 27px;
        color: #fff;
        padding: 0 12px;
        .edit {
          color: #fff;
          float: right;
          font-size: 16px;
          cursor: pointer;
          &:hover {
            opacity: .5;
          }
        }
        &:hover {
          .edit_item {
            display: block;
            animation: fade-in .3s;
          }
        }
        .edit_item {
          position: absolute;
          right: -200px;
          padding-left: 20px;
          top: 0;
          z-index: 101;
          display: none;
          .edit_item_content {
            width: 180px;
            box-sizing: border-box;
            background-color: #fff;
            color: #333;
            box-shadow: -3px 1px 13px 1px rgba(0, 0, 0, .3);
            border-radius: 4px;
            font-size: 12px;
            text-align: left;
            li {
              cursor: pointer;
              height: 40px;
              line-height: 40px;
              border-radius: 8px;
              text-align: center;
              border-bottom: 1px #efefef solid;
              span {
                display: inline-block;
                width: 80%;
                height: 26px;
                line-height: 26px;
                margin-top: 7px;
                border-radius: 8px;
                &.half {
                  width: 40%;
                  border-radius: 0;
                  &:first-child {
                    border-right: 1px #ddd solid;
                  }
                  &:hover {
                    color: $activeColor;
                  }
                }
              }
              &:hover {
                span:not(.half) {
                  background-color: $activeColor;
                  color: #fff;
                }
              }
            }
            &:before {
              content: "";
              position: absolute;
              left: 0px;
              top: 8px;
              width: 0;
              border: 10px transparent solid;
              border-right-color: #fff;
            }

          }
        }
      }
      .panel_body {
        line-height: 22px;
        padding: 10px 20px;
        font-size: 14px;
        text-align: left;
        color: #000;
        position: relative;
        &:hover {
          .hidden_div {
            display: block;
            height: 100px;
          }
        }
      }
      .hidden_div {
        background-color: $activeColor;
      }
    }
  }

  .org_info_modal_body {
    padding: 0 40px;
    height: 500px;
    .base_org_info_content {
      margin-bottom: 20px;
      height: 190px;
      overflow-y: auto;
      .title {
        line-height: 40px;
        border-bottom: 1px #efefef solid;
        position: relative;
        margin-bottom: 20px;
        .edit {
          color: #999;
          cursor: pointer;
          &:hover {
            color: $activeColor;
          }
        }
        &:after {
          content: "";
          position: absolute;
          left: 0;
          bottom: 0;
          width: 100px;
          height: 1px;
          background-color: $activeColor;
        }
      }
      .base_org_group_line {
        width: 50%;
        float: left;
        line-height: 30px;
        .key, .value {
          display: inline-block;
        }
        .value {
          padding-left: 8px;
        }
      }
    }
    table {
      width: 600px;
    }
  }

  .input_line {
    line-height: 50px;
    .label {
      display: inline-block;
      width: 40%;
      text-align: right;
      padding-right: 20px;
      position: relative;
      &.isMust:after {
        content: '*';
        color: #fabe05;
        position: absolute;
        right: 5px;
        font-size: 20px;
        line-height: 56px;
      }
    }
    .input {
      width: 40%;
    }
  }

  .btn_group {
    button {
      margin: 0 4px;
    }
    text-align: right;
  }

  .archive_content{
    padding: 10px 40px;
  }


  //动画
  @keyframes fade-in {
    0% {
      opacity: 0;
      transform: translate3d(0, -10%, 0);
    }
    100% {
      opacity: 1;
      transform: translate3d(0, 0, 0);
    }
  }

</style>
